package com.sskj.fabi.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.fabi.bean.FabiPayWayBean;
import com.sskj.fabi.bean.PayWayBean;
import com.sskj.fabi.bean.PublishPrice;
import com.sskj.fabi.http.HttpConfig;
import com.sskj.fabi.ui.activity.PublishActivity;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;


public class PublishActivityPresenter extends BasePresenter<PublishActivity> {
    // 获取支付方式
    public void requsetPayWayList() {
        httpService.getPayWayList()
                .execute(new JsonCallBack<HttpData<List<FabiPayWayBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<FabiPayWayBean>>> response) {
                        HttpData<List<FabiPayWayBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updatePayWay(httpData.getData());
                        }
                    }
                });

    }

    public void requsetPublish(boolean isBuy, String num, String min, String max, String price,
                               int payWx, int payAli, int payBank, String remark, String pwd) {
        httpService.fabiPublish(isBuy, num, min, max, price,
                payWx, payAli, payBank, remark, pwd)

                .execute(new JsonCallBack<HttpData>(this) {

                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.publishSuccess();
                        }
                    }
                });

    }

    // 获取单价
    public void requestUnitPrice() {
        OkGo.<HttpData<PublishPrice>>get(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_PRICELIMIT)
                .execute(new JsonCallBack<HttpData<PublishPrice>>() {

                    @Override
                    public void onSuccess(Response<HttpData<PublishPrice>> response) {

                        HttpData<PublishPrice> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updatePrice(httpData.getData().getTwd_usdt());
                        }
                    }
                });
    }

    public void cancelShop() {
        httpService.cancelShop()
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.cancelShopSuccess();
                        }
                    }
                });
    }
}
